package com.woniuxy.light_smart.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.light_smart.dto.FacDto;
import com.woniuxy.light_smart.service.FacilityService;
import com.woniuxy.light_smart.util.Result;
import com.woniuxy.light_smart.vo.FacEnvironmentVo;
import com.woniuxy.light_smart.vo.FacVo;
import com.woniuxy.light_smart.vo.LightPoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("fac")
public class FacilityController {
    @Autowired
    private FacilityService facilityService;

    @PostMapping("queryz")
    public Result queryFac1(@RequestBody FacDto facDto){
        PageHelper.startPage(facDto.getCurrentPage(), facDto.getPageSize());
        List<FacVo> facVos = facilityService.queryFac1(facDto);
        PageInfo<FacVo> pageInfo=new PageInfo(facVos);
        return Result.ok().data("zList",facVos).data("total",pageInfo.getTotal());
    }

    @PutMapping("updt")
    public Result updateFac(@RequestBody FacDto facDto){
        facilityService.updateFac(facDto);
        return Result.ok();
    }

    @PostMapping("queryh")
    public Result queryFac6(@RequestBody FacDto facDto){
        PageHelper.startPage(facDto.getCurrentPage(), facDto.getPageSize());
        List<FacEnvironmentVo> facVos = facilityService.queryFac6(facDto);
        PageInfo<FacEnvironmentVo> pageInfo=new PageInfo(facVos);
        return Result.ok().data("hList",facVos).data("total",pageInfo.getTotal());
    }

    @PostMapping("querys")
    public Result queryFac2(@RequestBody FacDto facDto){
        PageHelper.startPage(facDto.getCurrentPage(), facDto.getPageSize());
        List<FacVo> facVos = facilityService.queryFac2(facDto);
        PageInfo<FacVo> pageInfo=new PageInfo(facVos);
        return Result.ok().data("sList",facVos).data("total",pageInfo.getTotal());
    }
    @PostMapping("queryg")
    public Result queryFac3(@RequestBody FacDto facDto){
        PageHelper.startPage(facDto.getCurrentPage(), facDto.getPageSize());
        List<FacVo> facVos = facilityService.queryFac3(facDto);
        PageInfo<FacVo> pageInfo=new PageInfo(facVos);
        return Result.ok().data("gList",facVos).data("total",pageInfo.getTotal());
    }
    @PostMapping("queryw")
    public Result queryFac4(@RequestBody FacDto facDto){
        PageHelper.startPage(facDto.getCurrentPage(), facDto.getPageSize());
        List<FacVo> facVos = facilityService.queryFac4(facDto);
        PageInfo<FacVo> pageInfo=new PageInfo(facVos);
        return Result.ok().data("wList",facVos).data("total",pageInfo.getTotal());
    }
    @PostMapping("queryd")
    public Result queryFac5(@RequestBody FacDto facDto){
        PageHelper.startPage(facDto.getCurrentPage(), facDto.getPageSize());
        List<FacVo> facVos = facilityService.queryFac5(facDto);
        PageInfo<FacVo> pageInfo=new PageInfo(facVos);
        return Result.ok().data("dList",facVos).data("total",pageInfo.getTotal());
    }
    @PostMapping("queryq")
    public Result queryFac7(@RequestBody FacDto facDto){
        PageHelper.startPage(facDto.getCurrentPage(), facDto.getPageSize());
        List<FacVo> facVos = facilityService.queryFac7(facDto);
        PageInfo<FacVo> pageInfo=new PageInfo(facVos);
        return Result.ok().data("qList",facVos).data("total",pageInfo.getTotal());
    }
    @PostMapping("queryx")
    public Result queryFac8(@RequestBody FacDto facDto){
        PageHelper.startPage(facDto.getCurrentPage(), facDto.getPageSize());
        List<FacVo> facVos = facilityService.queryFac8(facDto);
        PageInfo<FacVo> pageInfo=new PageInfo(facVos);
        return Result.ok().data("xList",facVos).data("total",pageInfo.getTotal());
    }

    @DeleteMapping("{id}")
    public Result deleteByFacId(@PathVariable Long id){
        facilityService.deleteByPrimaryKey(id);
        return Result.ok();
    }

}
